Skip to main content

Setup a MongoDB database

MongoDB, a NoSQL database, is known for high performance and scalability. It's ideal for handling large data volumes in the Evolution API.

Set the MongoDB environment variables in the .env for Docker or the dev-env.yml for NPM file as follows:

.env or dev-env.yml
# Set to true to enable MongoDB.
DATABASE_ENABLED=true
# Your MongoDB connection string.
DATABASE_CONNECTION_URI=mongodb://user:password@database_URL/?authSource=admin&readPreference=primary&ssl=false&directConnection=true
# Prefix for your database name.
DATABASE_CONNECTION_DB_PREFIX_NAME=evo

Data migration

Switching from local storage to MongoDB will not automatically transfer your WhatsApp instances that are currently synchronized with the original local storage.

Beta: Data Migration

Make sure that you already have an MongoDB instance running with a database created.

Migrate your data in NPM or NVM

Stop the PM2 execution:

Flush and Stop: Clears all logs from PM2, useful for troubleshooting after the update and temporarily stops the Evolution API to safely apply updates.

CLI
# Clear all PM2 logs
pm2 flush

# Stop the current Evolution API process
pm2 stop ApiEvolution

Evolution API directory: access your directory installation with the following command:

cd evolution-api

Migrate command: Run the migration command in the installation directory:

/evolution-api/
npx evolution-manager api migrate-to-mongo

Follow the script steps and migrate specific WhatsApp instances or all your instances.